package com.rundow.common.sdk.init;

import com.rundow.common.base.exception.AlreadyExistException;
import com.rundow.common.sdk.bean.driver.ServiceContainerContext;
import com.rundow.common.sdk.factory.ServiceContainerFactory;
import com.rundow.common.sdk.service.DriverCommandService;
import com.rundow.common.sdk.service.DriverCustomService;
import com.rundow.common.sdk.service.DriverScheduleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ServiceContainerRegister {

    @Autowired
    public  ServiceContainerContext serviceContainerContext ;

    public void register(String driverName) {
        if (serviceContainerContext.containsKey(driverName)) {
            throw new AlreadyExistException("driver {} is already existed", driverName);
        }
        final ServiceContainerFactory serviceContainerFactory = new ServiceContainerFactory() {
            @Override
            public DriverCustomService createDriverCustomService() {
                return null;
            }

            @Override
            public DriverCommandService createdriverCommandService() {
                return null;
            }

            @Override
            public DriverScheduleService createdriverScheduleService() {
                return null;
            }
        };
        serviceContainerContext.put(driverName, serviceContainerFactory.createServiceContainer(driverName));

        log.info("serviceContainerContext={}",serviceContainerContext);
    }


}
